//
//  LWBaseViewController.swift
//  ios8-01 weibo框架搭建
//
//  Created by blue on 16/2/27.
//  Copyright © 2016年 honeywell. All rights reserved.
//

import UIKit

class LWBaseViewController: UITableViewController,LWVisterViewDelegate {
    
    
    var  userLogin = false
    
    
        //当用户没有登录，使用自定义的界面，如果用户－－＝＝＝＝＝
        
        override func loadView() {
            
            if(userLogin){
                
                super.loadView()
                
            }else{
                
                //走访客界面
                setupVistorView()
            }
            
            //4.设置代理
           // self.vistorView.registerDelegate? = self

            self.vistorView.registerDelegate = self
            
        }
    
    
    // MARK: - 5.实现代理方法
    func registerBtnClick() {
        
        print("代理注册")
    }
    
    func loginBtnClick() {
        
        print("代理登陆")
        
        let vc = LWOAthus()
        
        //包装到导航控制器
        let nav = UINavigationController(rootViewController: vc)
        
        nav.view.backgroundColor = UIColor.orangeColor()
        
        //跳转到这个控制器
        presentViewController(nav, animated: true, completion: nil)
        
        
        

    }
        func setupVistorView(){
            
            //self.view = LWVisterView()
            self.view = vistorView  //为什么这么设置
            self.view.backgroundColor = UIColor.whiteColor()
            
            
            self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registerBtnClick")
            
            self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "loginBtnClick")
            
            
            //在这里设置每个子控制器的访客视图==通过判断是哪一个控制器来设置不同的访客视图内容
            if self is LWHomeController{
                
                print("app启动好默认在这个控制器")
                
                //转盘转起来
                self.vistorView.iconViewAnimation()
                
            }else if(self is LWMessageController){
                
                print("消息访客视图")
                self.vistorView.setupVistorView("visitordiscover_image_message", title: "消息访客视图内容已设置")
                
            }else if(self is LWDiscoverController){
                
                print("发现访客视图")
                self.vistorView.setupVistorView("visitordiscover_image_message", title: "发现访客视图内容已设置")
                
            }else if(self is LWProfileController){
                
                print("我＝访客视图")
                self.vistorView.setupVistorView("visitordiscover_image_profile", title: "我的访客视图内容已经设置好")
                
            }
        
                      
        }

    
    lazy  var vistorView:LWVisterView = LWVisterView()
        
        
        
}
